//
//  IndexCollectionView.m
//  HWSGW
//
//  Created by avachen on 15/11/9.
//  Copyright © 2015年 luxuanrui. All rights reserved.
//

#import "IndexCollectionView.h"
#import "IndexCell.h"

#import "Movie.h"

#import "UIViewExt.h"


@implementation IndexCollectionView
{
    NSString *identify;
}
- (instancetype)initWithFrame:(CGRect)frame
{
   
    self = [super initWithFrame:frame];
    if (self) {
        
        identify = @"IndexCell";
        [self registerClass:[IndexCell class] forCellWithReuseIdentifier:identify];
        
        
    }
    //    self.contentInset = UIEdgeInsetsMake(0, 100, 0, 100);
    
    return self;
}
#pragma mark - UICollectionView delegate
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    IndexCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
    Movie *movie = self.data[indexPath.item];
    NSString *smallUrl = [movie.images objectForKey:@"small"];
    cell.url = smallUrl;
    
    return cell;
    
}
//点击翻转
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    //单元格点击居中
    if (self.currentItem != indexPath.item) {
        [collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
        
        self.currentItem = indexPath.item;
        
    }
    
    
}
@end
